package br.edu.unifei.mestrado.fm;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Block implements Iterable<Integer>{

	private Logger logger = LoggerFactory.getLogger(this.getClass());

	//netId | size
	//TODO: a chave é netId ou cellId??????????????
	private Map<Long, Integer> map = new HashMap<Long, Integer>();

	public void increment(Net net) {
		Integer value = map.get(net.getId());
		if (value == null) {
			value = 1;
		} else {
			value++;
		}
		map.put(net.getId(), value);
	}
	
	public void decrement(Net net) {
		Integer value = map.get(net.getId());
		if (value != null) {
			value--;
		}
		map.put(net.getId(), value);
	}

	public void print(String name) {
		logger.debug("{} {}", name, this);
	}

	@Override
	public String toString() {
		return map.toString();
	}
	
	@Override
	public Iterator<Integer> iterator() {
		return map.values().iterator();
	}
	
	public Integer getSizeOf(Net net) {
		if(map.containsKey(net.getId())) {
			return map.get(net.getId());
		}
		return Integer.MIN_VALUE;
//		throw new RuntimeException("Net id não encontrado: " + net.getId());
	}
}
